 package handling.channel.handler;

 import client.MapleClient;
 import handling.world.WorldGuildService;
 import handling.world.guild.MapleBBSThread;
 import java.util.List;
 import tools.data.input.LittleEndianAccessor;
 import tools.packet.GuildPacket;


 public class BBSHandler
 {
   private static String correctLength(String in, int maxSize) {
/*  14 */     if (in.length() > maxSize) {
/*  15 */       return in.substring(0, maxSize);
     }
/*  17 */     return in; } public static void BBSOperation(LittleEndianAccessor slea, MapleClient c) {
     boolean bEdit, bNotice;
     String title, text;
     int icon, start, replyid;
/*  21 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/*  24 */     int localthreadid = 0;
/*  25 */     byte action = slea.readByte();
/*  26 */     switch (action) {
       case 0:
/*  28 */         bEdit = (slea.readByte() > 0);
/*  29 */         if (bEdit) {
/*  30 */           localthreadid = slea.readInt();
         }
/*  32 */         bNotice = (slea.readByte() > 0);
/*  33 */         title = correctLength(slea.readMapleAsciiString(), 25);
/*  34 */         text = correctLength(slea.readMapleAsciiString(), 600);
/*  35 */         icon = slea.readInt();
/*  36 */         if (icon >= 100 && icon <= 106) {
/*  37 */           if (!c.getPlayer().haveItem(5290000 + icon - 100, 1, false, true)) {
             return;
           }
/*  40 */         } else if (icon < 0 || icon > 2) {
           return;
         }
/*  43 */         if (!bEdit) {
/*  44 */           newBBSThread(c, title, text, icon, bNotice); break;
         }
/*  46 */         editBBSThread(c, title, text, icon, localthreadid);
         break;

       case 1:
/*  50 */         localthreadid = slea.readInt();
/*  51 */         deleteBBSThread(c, localthreadid);
         break;
       case 2:
/*  54 */         start = slea.readInt();
/*  55 */         listBBSThreads(c, start * 10);
         break;
       case 3:
/*  58 */         localthreadid = slea.readInt();
/*  59 */         displayThread(c, localthreadid);
         break;
       case 4:
/*  62 */         localthreadid = slea.readInt();
/*  63 */         text = correctLength(slea.readMapleAsciiString(), 25);
/*  64 */         newBBSReply(c, localthreadid, text);
         break;
       case 5:
/*  67 */         localthreadid = slea.readInt();
/*  68 */         replyid = slea.readInt();
/*  69 */         deleteBBSReply(c, localthreadid, replyid);
         break;
     }
   }

   private static void listBBSThreads(MapleClient c, int start) {
/*  75 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/*  78 */     c.announce(GuildPacket.BBSThreadList(WorldGuildService.getInstance().getBBS(c.getPlayer().getGuildId()), start));
   }

   private static void newBBSReply(MapleClient c, int localthreadid, String text) {
/*  82 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/*  85 */     WorldGuildService.getInstance().addBBSReply(c.getPlayer().getGuildId(), localthreadid, text, c.getPlayer().getId());
/*  86 */     displayThread(c, localthreadid);
   }

   private static void editBBSThread(MapleClient c, String title, String text, int icon, int localthreadid) {
/*  90 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/*  93 */     WorldGuildService.getInstance().editBBSThread(c.getPlayer().getGuildId(), localthreadid, title, text, icon, c.getPlayer().getId(), c.getPlayer().getGuildRank());
/*  94 */     displayThread(c, localthreadid);
   }

   private static void newBBSThread(MapleClient c, String title, String text, int icon, boolean bNotice) {
/*  98 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/* 101 */     displayThread(c, WorldGuildService.getInstance().addBBSThread(c.getPlayer().getGuildId(), title, text, icon, bNotice, c.getPlayer().getId()));
/* 102 */     listBBSThreads(c, 0);
   }

   private static void deleteBBSThread(MapleClient c, int localthreadid) {
/* 106 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/* 109 */     WorldGuildService.getInstance().deleteBBSThread(c.getPlayer().getGuildId(), localthreadid, c.getPlayer().getId(), c.getPlayer().getGuildRank());
   }

   private static void deleteBBSReply(MapleClient c, int localthreadid, int replyid) {
/* 113 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }

/* 117 */     WorldGuildService.getInstance().deleteBBSReply(c.getPlayer().getGuildId(), localthreadid, replyid, c.getPlayer().getId(), c.getPlayer().getGuildRank());
/* 118 */     displayThread(c, localthreadid);
   }

   private static void displayThread(MapleClient c, int localthreadid) {
/* 122 */     if (c.getPlayer().getGuildId() <= 0) {
       return;
     }
/* 125 */     List<MapleBBSThread> bbsList = WorldGuildService.getInstance().getBBS(c.getPlayer().getGuildId());
/* 126 */     if (bbsList != null)
/* 127 */       for (MapleBBSThread t : bbsList) {
/* 128 */         if (t != null && t.localthreadID == localthreadid)
/* 129 */           c.announce(GuildPacket.showThread(t)); 
       }
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\BBSHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */